package com.small.os.minio.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.small.os.minio.entity.AqShareFavorites;
import com.small.os.minio.mapper.AqShareFavoritesMapper;
import com.small.os.minio.service.IAqShareFavoritesService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 收藏夹 服务实现类
 * </p>
 *
 * @author Z.WY
 * @since 2020-11-20
 */
@Service
public class AqShareFavoritesServiceImpl extends ServiceImpl<AqShareFavoritesMapper, AqShareFavorites> implements IAqShareFavoritesService {

    @Override
    public void favorites(String jwCloudUserId, String shareId) {
        LambdaQueryWrapper<AqShareFavorites> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AqShareFavorites::getAqShareId, shareId)
                .eq(AqShareFavorites::getJwCloudUserId, jwCloudUserId);
        int count = this.count(wrapper);
        if (count <= 0) {
            AqShareFavorites aqShareFavorites = new AqShareFavorites();
            aqShareFavorites.setAqShareId(shareId);
            aqShareFavorites.setJwCloudUserId(jwCloudUserId);
            this.save(aqShareFavorites);
        }else {
            this.remove(wrapper);
        }
    }
}
